<?php 
	require_once ('checks.php');
	require_once ('Database.php');
	require_once ('News.php');
	$db = new DB();
	if (isset($_POST['go']) && isset($_POST['news_name'])) {
		
		$news= $db->extractNews($_POST['news_name']);
		$arr = $db->findName("news");
		$newsarr= sortBy($arr, "order" , "asc");	
		$n= count($newsarr);
		for ($i=0;$i<$n;$i++){
			if ($newsarr[$i]->getId()==$news->getId()){
				$idx=$i;
				break;
			}
		}
		$newsarr = $db->reOrderObjArray($newsarr, $idx, $n);
		for ($i=$idx;$i<$n;$i++){
			$db->updateNews($newsarr[$i]);
		}
		$db->deleteRecordInNews($news);
	}
 ?>

		
		<form method="post" action="?page=admin_delete_news">
			<table>
				<tr>
					<td><label for="news">News Name : </label>
					</td>
					<td><select name="news_name" id="news">
							<?php
								$arr = $db->findName("news");
								$n= count($arr);
								for ($i=0;$i<$n;$i++) {
									echo "<option value='$arr[$i]'>$arr[$i]";
								}
							?>
					</select>
					</td>
				</tr>
				<tr>
					<td>						
					</td>
					<td ><input type="submit" value=" Delete " name="go" onclick="return confirm('Сигурни ли сте че искате да я изтриете?');">

					</td>				
				</tr>
			</table>
		</form>
